package display;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;

import javax.swing.JPanel;

import universe.Block;

public class NextBlockDisplay extends JPanel {
	private Block nextBlock;
	private Container theContainer;
	
	
	public NextBlockDisplay(Container pContainer,Block pBlock){
		super();
		theContainer = pContainer;
		this.setBlock(pBlock);
		
		this.setSize(display.Utils.getNextBlockDisplayWidthPx+Utils.paddingFrame, display.Utils.getNextBlockDisplayHeightPx+Utils.paddingFrame);
		
		theContainer.add(this);
	}
	
	public void setBlock(Block pBlock){
		nextBlock = pBlock;
	}
	
	public void paintComponent(Graphics g){
		int initialPointX = (display.Utils.getNextBlockDisplayWidthPx /2) - ((nextBlock.getMinimalWidth() * display.Utils.sideWidth) /2);
		int initialPointY = (display.Utils.getNextBlockDisplayHeightPx /2) - ((nextBlock.getMinimalHeight() * display.Utils.sideWidth) /2);
		int [][] minimalMatrix = nextBlock.getMinimalMatrix();
		

		Color theColor = new Color(Utils.nextBlockDisplayColor.getRed(), Utils.nextBlockDisplayColor.getGreen(), Utils.nextBlockDisplayColor.getBlue(), display.Utils.nextBlockDisplayAlpha);
		g.setColor(theColor);
		g.fill3DRect(Utils.paddingFrame, Utils.paddingFrame,display.Utils.getNextBlockDisplayWidthPx, display.Utils.getNextBlockDisplayHeightPx,true);

	
		for(int i=0; i<nextBlock.getMinimalWidth();i++){
			for(int j=0; j<nextBlock.getMinimalHeight();j++){	
				if(minimalMatrix[i][j] != 0){
					g.setColor(Utils.getColor(minimalMatrix[i][j]));
					g.fill3DRect(Utils.paddingFrame+initialPointX+(i*display.Utils.sideWidth), (Utils.paddingFrame+initialPointY + (j*display.Utils.sideWidth)), Utils.sideWidth, Utils.sideWidth,true);
				}
			}
		}
	}
	
	
}
